Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Create API Token" and "Delete API Token" calls #148

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

WRansohoff
Copy link

Hello,

A few weeks ago, we discussed submitting a pull request with the "create / delete API token" logic that we have been using to programmatically set up API keys using the axiom-py package. Sorry for the delay in submitting this - I was OOTO recently and just got around to it.

The logic should be fairly simple, and I did my best to structure the API parameters according to your documentation and existing conventions. But please let me know if you have any questions or concerns.

Thank you!

Copy link
Member

@bahlo bahlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your contribution! Left a few notes, very happy to pair on the tokens client if you want ☺️

Comment on lines +15 to +26
# Ability to ingest data. Optional.
ingest: Optional[list[Literal["create"]]] = field(default=None)
# Ability to query data. Optional.
query: Optional[list[Literal["read"]]] = field(default=None)
# Ability to use starred queries. Optional.
starredQueries: Optional[
list[Literal["create", "read", "update", "delete"]]
] = field(default=None)
# Ability to use virtual fields. Optional.
virtualFields: Optional[
list[Literal["create", "read", "update", "delete"]]
] = field(default=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing data, trim and vacuum:

Suggested change
# Ability to ingest data. Optional.
ingest: Optional[list[Literal["create"]]] = field(default=None)
# Ability to query data. Optional.
query: Optional[list[Literal["read"]]] = field(default=None)
# Ability to use starred queries. Optional.
starredQueries: Optional[
list[Literal["create", "read", "update", "delete"]]
] = field(default=None)
# Ability to use virtual fields. Optional.
virtualFields: Optional[
list[Literal["create", "read", "update", "delete"]]
] = field(default=None)
# Data management capability. Optional.
data: Optional[list[Literal["delete"]]] = field(default=None)
# Ability to ingest data. Optional.
ingest: Optional[list[Literal["create"]]] = field(default=None)
# Ability to query data. Optional.
query: Optional[list[Literal["read"]]] = field(default=None)
# Ability to use starred queries. Optional.
starredQueries: Optional[
list[Literal["create", "read", "update", "delete"]]
] = field(default=None)
# Trim capability. Optional
trim: Optional[list[Literal["update"]]] = field(default=None)
# Vacuum capability. Optional
vacuum: Optional[list[Literal["update"]]] = field(default=None)
# Ability to use virtual fields. Optional.
virtualFields: Optional[
list[Literal["create", "read", "update", "delete"]]
] = field(default=None)

apiTokens: Optional[
list[Literal["create", "read", "update", "delete"]]
] = field(default=None)
# Ability to access billing. Optional.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing audit log:

Suggested change
# Ability to access billing. Optional.
# Audit log capability. Optional.
auditLog: Optional[
list[Literal["read"]]
] = field(default=None)
# Ability to access billing. Optional.

Comment on lines +316 to +329
def create_api_token(self, opts: TokenAttributes) -> Token:
"""Creates a new API token with permissions specified in a TokenAttributes object."""
res = self.session.post(
"/v2/tokens",
data=ujson.dumps(asdict(opts), default=handle_json_serialization),
)

# Return the new token and ID.
response = res.json()
return Token(id=response["id"], token=response["token"])

def delete_api_token(self, token_id: str) -> None:
"""Delete an API token using its ID string."""
self.session.delete(f"/v2/tokens/{token_id}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this into a TokenClient in tokens.py, similar to

class DatasetsClient: # pylint: disable=R0903
"""DatasetsClient has methods to manipulate datasets."""
session: Session
def __init__(self, session: Session):
self.session = session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants